package com.lpit.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lpit.constant.Constant;
import com.lpit.dto.CertificationDto;
import com.lpit.pojo.Certification;
import com.lpit.service.CertificationService;
import com.lpit.mapper.CertificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【certification(实名认证表)】的数据库操作Service实现
 * @createDate 2023-06-14 14:57:24
 */
@Service
public class CertificationServiceImpl extends ServiceImpl<CertificationMapper, Certification>
        implements CertificationService {

    @Autowired
    private CertificationMapper certificationMapper;

    /*查看所有审核用户*/
    @Override
    public IPage<CertificationDto> lookCertificationList(Integer page, Integer pageSize) {
        IPage<CertificationDto> objectPage = new Page<>(page,pageSize);
        /*调用dao层查询*/
        return certificationMapper.lookCertificationList(objectPage);
    }

    /*根据id批量修改认证状态*/
    @Override
    public boolean updateCertificationStatus(List<Integer> integers,String status) {
        /*判断请求是否是通过审批的，是通过审批就将状态修改为通过，否则就是驳回*/
        status = status.equals(Constant.HTTP_REJECT_URI) ? Constant.CERTIFICATION_STATUS_REJECT : Constant.CERTIFICATION_STATUS_PASS;
        /*创建集合容器*/
        List<Certification> statusList = new ArrayList<>();
        /*循环创建修改信息对象，将对象传入list*/
        for (Integer integer : integers) {
            Certification certification = new Certification();
            certification.setId(integer);
            certification.setCertificationStatus(status);
            statusList.add(certification);
        }
        /*调用mybatisPlus批量修改方法并返回结果*/
        return this.updateBatchById(statusList);
    }
}




